<#include "/common/head2.html"/> 
<div class="easyui-panel addPage" data-options="fit:true,border:false,novalidate:true">
	<form class="easyui-form" id="ff" method="post" data-options="novalidate:true">
		
		<div id="tb" style="padding:2px 5px;">
			<a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="searchback()">返回</a>
		</div>
		
		<table>
			<tr>
				<td>
					<span class="adertisement">商户名称: </span>
				    <input required="ture" class="easyui-validatebox" type="text" id="name" name="name" value="" />
				</td>
				
				
				<td>
             		<span class="search_item">
					 			<span class="adertisement">商户类型: </span>
				            	<select class="easyui-combobox" name="type" id="type" style="width:100px" >
						           	   <option value ="0">个体</option>
                                      
                                       <option value ="1">企业</option>
                                </select>
                    </span> 
            	</td> 
				
			</tr>
			
			<tr>
            	
            	
            	<td><span class="adertisement">选择服务: </span>
					<select class="easyui-combobox" id="serviceId" name="serviceId" >
							  <option></option>
				 		  	  <option value ="1">反欺诈</option>
                              <option value ="2">评分卡</option>
				    </select>
				    <span class="adertisement">选择规则集: </span>
				    
				    <select class="easyui-combobox" id="ruleSetId" name="ruleSetId" >
				    </select>
				    <input type="hidden" id="fan_span_hidden" name="service_span" value="fan_span_hidden"/>
				    <input type="hidden" id="gui_span_hidden" name="ruleSet_span" value="gui_span_hidden"/>
			   </td>
            </tr>		
				
		 	<tr>
				<td>
					<span class="adertisement">预存款: </span>
				    <input required="required" type="text" id="money" name="money" value="0.0" maxlength="9"/>
				</td>
			</tr>
				<tr>
				<td>
					<span class="adertisement">账号: </span>
				  	<input  type="text" id="username" name="username" value=""  readonly="readonly"/>
				</td>
			</tr>
			<tr>
				<td>
					<span class="adertisement">密码: </span>
				   	<input  type="text" id="pwd" name="pwd" value="123456"   readonly="readonly"/>
				</td>
			</tr> 
			<tr>
            	<td>
	            	<div data-options="region:'south',border:false" style="text-align: right; padding: 12px; border-top-width: 0px; border-top-style: solid; border-top-color: rgb(221, 221, 221); width: 674px; height: 28px;" title="" class="panel-body panel-body-noheader panel-body-noborder layout-body">
	            		<a class="easyui-linkbutton color1 l-btn l-btn-small" href="javascript:void(0)" onclick="javascript:save();" style="width: 220px;">
	            			<span class="l-btn-center" style="margin-top: 0px;"><span class="l-btn-text">确定</span></span>
	            		</a>
	        		</div>
            	</td>
            </tr>			
		</table>
	</form>
</div>
<script type="text/javascript">
var j=null;
var j2=null;

$("#serviceId").combobox({
	onChange:function(){
		
		var jia=$("#serviceId").combobox('getText');
		if(j==null){
			j=jia;
			$("#fan_span").text(j);
			var v1=$("#serviceId").combobox('getValue');
			$("#fan_span_hidden").val(v1);
		}else{
			stringText = jia;
			$("#fan_span2").text(jia);
			var v2=$("#serviceId").combobox('getValue');
			$("#fan_span_hidden2").val(v2);
		}
		
	}
});

$("#ruleSetId").combobox({
	onChange:function(){
		if($("#serviceId").combobox('getValue')=='' || $("#serviceId").combobox('getValue')==null){
			$('#ruleSetId').combobox('setValue','');
			return;
		}
		var jia=$("#ruleSetId").combobox('getText');
		if(j2==null){
			j2=jia;
			$("#gui_span").text(j2);
			var v3=$("#serviceId").combobox('getValue');
			$("#gui_span_hidden").val(v3);
		}else{
			$("#gui_span2").text(jia);
			var v4=$("#serviceId").combobox('getValue');
			$("#gui_span_hidden2").val(v4);
		}
	}
});

$.ajax({ 
    type : "POST", //提交方式 
    url : "find",//路径 
    success : function(result) {//返回数据根据结果进行相应的处理 
	var data = [];
    for(var i=0;i<result.length;i++){
    	var value = result[i].id;
    	var text = result[i].name;
    	data.push({"text":text,"value":value});
    }
    $("#ruleSetId").combobox("loadData",data);////此时我们便将所有option添加到select中了
    },
    error: function (data){
    	
    }
   });
   

function save() {
	
	if($("#name").val()==''){
		$.messager.alert('提示','请输入商户名称');
		return;
	} 
	
	if($("#fan_span_hidden").val()==''){
		$.messager.alert('提示','请选择服务');
		return;
	}else{
		if($("#gui_span_hidden").val()==''){
			$.messager.alert('提示','请选择规则集');
			return;
		} 
	}
	
	if($("#money").val()==''){
		$.messager.alert('提示','填写预存款');
		return;
	}
	 $("#ff").form('submit', { 
        url: "add", 
        onSubmit: function () {   
        	//表单提交前的回调函数 
        	if(!$("#ff").form('enableValidation').form('validate')) {
            	$.messager.alert('操作结果','请检查标红输入项','error');
        		return false;
        	}       	
        	
        }, 
        success: function (v) {
        	location.replace("list")
    	} 
      });  
	
	
}
//js扩展功能
function keyPress() {    
		         var keyCode = event.keyCode;    
		         if ((keyCode >= 48 && keyCode <= 57) ||(keyCode >=65 && keyCode <= 90) || (keyCode >=97 && keyCode<=122) || (keyCode == 95)){    
		             event.returnValue = true;    
		         } else {    
		               event.returnValue = false;    
		        }    
		     } 
/** 
* 返回一个随机的大写字母 
*/
var str=getUpperCharacter()+getUpperCharacter()+rnd(0,9)+rnd(0,9)+rnd(0,9)+rnd(0,9);
$("#username").val(str);
function getUpperCharacter(){ 
return getCharacter("upper");; 
} 
 
/** 
* 返回一个字母 
*/
function getCharacter(flag){ 
var character = ""; 
if(flag === "upper"){ 
character = String.fromCharCode(Math.floor( Math.random() * 26) + "A".charCodeAt(0)); 
} 
return character; 
} 


var str2=rnd(0,9);
function rnd(min, max){
	  return min + Math.floor(Math.random() * (max - min + 1));
	}
		
//返回	
function searchback() {
	location.replace("list");
}
//产品价格配置
function add(){
	location.replace("allocation");
}


</script>
<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>